﻿#include "widget.h"
#include "ui_widget.h"
#include <QQuickWidget>
#include <QPixmap>
#include <QPalette>
#include <QColor>
#include <QQmlEngine>
#include <QQmlContext>
#include <QDate>
#include <QSettings>
#include <QDir>
#include <QTextStream>
#include <QDesktopWidget>
#include <QApplication>
#include <QDebug>
#include <iostream>

#include "game.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget),
    w(400),
    h(300)
{
    ui->setupUi(this);

    ui->quickWidget->engine()->rootContext()->setContextProperty("widget",this);

    ui->quickWidget->setSource(QUrl("qrc:/qml/main.qml"));

    this->setFixedSize(w, h);

    setWindowTitle("Iterator");

    List<int> aList(5);
    for(int i=0;i<5;i++)
        aList.Set(i, i);
    for(int i=0;i<aList.Count();++i)
        std::cout << aList.Get(i) << " ";

    std::cout << "\n";

    IteratorPtr<int> iteratorPtr(new ListIterator<int>(&aList));
    for(iteratorPtr->First(); !iteratorPtr->IsDone(); iteratorPtr->Next())
    {
        std::cout << iteratorPtr->CurrentItem() << " ";
    }

    // test
    iteratorPtr->Next();
    try
    {
        std::cout << iteratorPtr->CurrentItem();
    }
    catch(IteratorOutOfBounds e)
    {
        std::cout << e.what();
    }

}

Widget::~Widget()
{
    delete ui;
}

void Widget::systemExit(bool b)
{    
    (void)b;
    qApp->quit();
}
